/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.Materia;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Andreina Wilhelm
 */
public class ConsultarMateriaForm extends org.apache.struts.action.ActionForm {

    private String materiaCod;
    private Materia materiaSelected;

    public String getMateriaCod() {
        return materiaCod;
    }

    public void setMateriaCod(String materiaCod) {
        this.materiaCod = materiaCod;
    }

    public Materia getMateriaSelected() {
        return materiaSelected;
    }

    public void setMateriaSelected(Materia materiaSelected) {
        this.materiaSelected = materiaSelected;
    }

    /**
     *
     */
    public ConsultarMateriaForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

        // validar el seleccionado no sea Seleccione...
        if (this.materiaCod.equals("Seleccione...")) {
            errors.add("err_selec", new ActionMessage("errors.select"));    // agrego un error porque sino no agarra camino que deberia pero esto no lo voy a mostrar
        }

        return errors;
    }

    
    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset properties
        this.materiaCod = "";
        this.materiaSelected = null;
    }
}
